package com.relife.common.model;

import com.relife.common.utils.StringUtil;
import com.relife.core.entity.*;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class Client implements Serializable {

	private static final long serialVersionUID = -4210497672168586126L;
	/** 登录公司 **/
	private String sessionId;
	/** 登录公司 **/
	private DepartmentEntity company;
	/** 登录部门 **/
	private DepartmentEntity depart;
	/** 用户 **/
	private UserEntity user = null;
	/** 浏览器 **/
	private String browser;
	/** IP **/
	private String ip;
	/** 登录时间 **/
	private Date loginTime;
	/** 样式风格 **/
	private String theme = "default";

	private Integer departSize;
	/** 用户角色列表 **/
	private List<RoleEntity> roleList = new ArrayList<RoleEntity>();
	/** 菜单权限列表 **/
	private List<FunctionEntity> fList = new ArrayList<FunctionEntity>();
	/** 按钮权限 **/
	private Map<String, FunctionEntity> butMap = new HashMap<String, FunctionEntity>();
	/** 数据权限列表 **/
	private List<PermissionEntity> preList = new ArrayList<PermissionEntity>();
	/** 部门列表 **/
	private List<DepartmentEntity> departList = new ArrayList<DepartmentEntity>();
	/** 配置的页面 **/
	private List<HomeSettingEntity> homeSetList = new ArrayList<HomeSettingEntity>();

	public UserEntity getUser() {
		return user;
	}

	public void setUser(UserEntity user) {
		this.user = user;
	}

	public List<FunctionEntity> getfList() {
		return fList;
	}

	public void setfList(List<FunctionEntity> fList) {
		this.fList = fList;
	}

	public Map<String, FunctionEntity> getButMap() {
		return butMap;
	}

	public void setButMap(Map<String, FunctionEntity> butMap) {
		this.butMap = butMap;
	}

	public List<PermissionEntity> getPreList() {
		return preList;
	}

	public void setPreList(List<PermissionEntity> preList) {
		this.preList = preList;
	}

	public String getBrowser() {
		return browser;
	}

	public void setBrowser(String browser) {
		this.browser = browser;
	}

	public List<RoleEntity> getRoleList() {
		return roleList;
	}

	public void setRoleList(List<RoleEntity> roleList) {
		this.roleList = roleList;
	}

	public DepartmentEntity getDepart() {
		return depart;
	}

	public void setDepart(DepartmentEntity depart) {
		this.depart = depart;
	}

	public List<DepartmentEntity> getDepartList() {
		return departList;
	}

	public void setDepartList(List<DepartmentEntity> departList) {
		this.departList = departList;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public Timestamp getLoginTime() {
		return new Timestamp(loginTime.getTime());
	}

	public void setLoginTime(Date loginTime) {
		this.loginTime = loginTime;
	}

	public boolean hasRole(String roleCode) {
		for (int i = 0; i < this.roleList.size(); i++) {
			if ("roleCode".equals(roleList.get(i).getDepCode())) {
				return true;
			}
		}
		return false;
	}

	public Integer getDepartSize() {
		departSize = getDepartList().size();
		return departSize;
	}

	public void setDepartSize(Integer departSize) {
		this.departSize = departSize;
	}

	public DepartmentEntity getCompany() {
		return company;
	}

	public void setCompany(DepartmentEntity company) {
		this.company = company;
	}

	public void clear() {
		this.roleList.clear();
		this.butMap.clear();
		this.preList.clear();
		this.fList.clear();
		this.homeSetList.clear();
	}

	public String getSessionId() {
		return sessionId;
	}

	public void setSessionId(String sessionId) {
		this.sessionId = sessionId;
	}

	public String getTheme() {
		return theme;
	}

	public void setTheme(String theme) {
		if (StringUtil.isNotEmpty(theme)) {
			this.theme = theme;
		}
	}

	public List<HomeSettingEntity> getHomeSetList() {
		return homeSetList;
	}

	public void setHomeSetList(List<HomeSettingEntity> homeSetList) {
		this.homeSetList = homeSetList;
	}

}
